using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class NewsComment
    {
           #region Common
        public eNewsComment   Data;

        public NewsComment()
        {
            Data = new eNewsComment();
		}

        ~NewsComment()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cNewsComment objDAL = new cNewsComment();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cNewsComment objDAL = new cNewsComment();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cNewsComment objInfor = new cNewsComment(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.CommentID ;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cNewsComment objInfor = new cNewsComment();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cNewsComment objDAL = new cNewsComment();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;

                objDAL.Save();
                nResult = objDAL.CommentID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
     

        private void MappingData(cNewsComment objInfor)
        {
            objInfor.NewsID = Data.NewsID;
            objInfor.Dateposted = Data.Dateposted;
            objInfor.Content = Data.Content;
            objInfor.Email = Data.Email;
            objInfor.Status = Data.Status; 
        }

        private void ConvertData(cNewsComment objInfor)
        {
            Data.NewsID=objInfor.NewsID  ;
            Data.Dateposted =objInfor.Dateposted  ;
            Data.Content=objInfor.Content ;
            Data.Email = objInfor.Email;
            Data.Status   =objInfor.Status ; 
        }

        public DataTable Search(int ItemView, string Title, int NewsID, int Status, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cNewsComment objDAL = new cNewsComment();
            tbResult = objDAL.Search( ItemView,  Title,  NewsID,  Status,  PageIndex,  PageSize, ref  PageCount);
            return tbResult;
        }

        #endregion
    }
}
